<?php
function FillForm($str)
{
	global $TeamBool;
	if($TeamBool) return $str;
	return "";
}
function myMQpro($obj)
{
	return mysql_real_escape_string(trim($obj)); 
}
function SqlToHtml($str)
{return htmlspecialchars(stripslashes($str));}

function If_Require($Ckind)
{
	if($Ckind == 0) echo 'class="req"';
	else echo"";
}
function If_Star($Ckind)
{
	if($Ckind == 0) echo '<font color=red>*</font>';
	else echo"";
}
function if_reg_ing($SRtime, $ERtime, $now)
{
	if ($now>$ERtime) echo "<span class=green>注册已结束</span>";
	else if ($now<$SRtime) echo "<span class=blue>注册未开始</span>";
	else echo "<span class=red>注册开放中</span>";
}

function witchstart($start0, $start1, $active0, $active1, $view0, $view1)
{
	if($active0 == 'Y' && $active1 == 'Y')
		return $start0 < $start1 ? $view0 : $view1;
	else if($active0 == 'Y')
		return $view0;
	return $view1;
}
function witchend($end0, $end1, $active0, $active1, $view0, $view1)
{
	if($active0 == 'Y' && $active1 == 'Y')
		return $end0 > $end1 ? $view0 : $view1;
	else if($active0 == 'Y')
		return $view0;
	return $view1;
}

function do_download($file_addr, $rz)
{
	if (file_exists($file_addr)) 
	{    
	    header('Content-Description: File Transfer');    
	    if($rz == "rar")
		{
			Header("content-type:application/octet-stream"); 
		}
		else if($rz == "zip")
		{ 
			Header("content-type:application/x-zip-compressed"); 
		} 
		ob_end_clean();
	    header('Content-Disposition: attachment; filename='.basename($file_addr));    
	    header('Content-Transfer-Encoding: binary');    
	    header('Expires: 0');    
	    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');    
	    header('Pragma: public');    
	    header('Content-Length: ' . filesize($file_addr));    
	    ob_clean();   //重要的就是这个函数的调用， 清空但不关闭输出缓存， 否则下载的文件头两个字符会是0a 
	    flush();    
	    readfile($file_addr);   // 输出文件内容 
	} 
	else
	{
			echo "<script language='javascript'>\n";
			echo "alert('文件不存在!');\n";
			echo "history.go(-1);\n";
			echo "</script>";
			exit(0);
	}
}
?>
